package jjn.carl.hashtable;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Jiang Jining
 * @since 2023-07-04 21:33
 */
public class LeetCode454 {
    public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        Map<Integer, Integer> map = new HashMap<>();
        int res = 0;
        for (int first : nums1) {
            for (int second : nums2) {
                map.put(first + second, map.getOrDefault(first + second, 0) + 1);
            }
        }
        for (int third : nums3) {
            for (int fourth : nums4) {
                res += map.getOrDefault(-third - fourth, 0);
            }
        }
        return res;
    }
    
    public static void main(String[] args) {
        int[] nums1 = new int[]{1, 2};
        int[] nums2 = new int[]{-2, -1};
        int[] nums3 = new int[]{-1, 2};
        int[] nums4 = new int[]{0, 2};
        int fourSumCount = new LeetCode454().fourSumCount(nums1, nums2, nums3, nums4);
        System.out.println("fourSumCount = " + fourSumCount);
    }
}
